package com.starrtc.demo.imclient.kcp.usmp;

import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;



@ChannelHandler.Sharable
public class UmspConnectionHandler extends ChannelInboundHandlerAdapter {
    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        super.channelActive(ctx);
//        log.info("channelActive:" + ctx.channel().remoteAddress());
    }

    @Override
    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
        super.channelInactive(ctx);
//        log.info("channelInactive:" + ctx.channel().remoteAddress());
        ctx.close();
        handlerDisconnect(ctx);

    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { // (4)
        // Close the connection when an exception is raised.
//        log.warn("exceptionCaught:" + ctx.channel().remoteAddress() + " cause: " + cause);
        ctx.close();
    }

    public static void handlerDisconnect(ChannelHandlerContext ctx) {
//        int userID = ChannelRouter.getInstance().unRegisterRouter(ctx.channel());
//        ctx.fireUserEventTriggered(Event.buildEvent(Event.USER_EXIT_ROOM,userID));
    }
}
